/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author damfercer
 */
@Entity
@Table(name = "company")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Company.findAll", query = "SELECT c FROM Company c"),
    @NamedQuery(name = "Company.findByIdCompany", query = "SELECT c FROM Company c WHERE c.idCompany = :idCompany"),
    @NamedQuery(name = "Company.findByName", query = "SELECT c FROM Company c WHERE c.name = :name"),
    @NamedQuery(name = "Company.findByLogo", query = "SELECT c FROM Company c WHERE c.logo = :logo"),
    @NamedQuery(name = "Company.findByAvailableCredits", query = "SELECT c FROM Company c WHERE c.availableCredits = :availableCredits")})
public class Company implements Serializable {
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "company")
    private List<CompanyOrder> companyOrderList;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "company")
    private CompanyConfiguration companyConfiguration;
    @Size(max = 1024)
    @Column(name = "SUMMARY")
    private String summary;
    @Size(max = 100)
    @Column(name = "BUSINESS_NAME")
    private String businessName;
    @Size(max = 30)
    @Column(name = "CIF")
    private String cif;
    @Size(max = 70)
    @Column(name = "CONTACT")
    private String contact;
    // @Pattern(regexp="^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$", message="Invalid phone/fax format, should be as xxx-xxx-xxxx")//if the field contains phone or fax number consider using this annotation to enforce field validation
    @Size(max = 20)
    @Column(name = "PHONE")
    private String phone;
    @Size(max = 100)
    @Column(name = "ADDRESS")
    private String address;
    @Size(max = 10)
    @Column(name = "POSTAL_CODE")
    private String postalCode;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idCompany", fetch = FetchType.LAZY)
    private List<CompanyVisitedProfile> companyVisitedProfileList;
    @JoinColumn(name = "PROVINCE", referencedColumnName = "ID_PROVINCE")
    @ManyToOne(fetch = FetchType.LAZY)
    private Province province;
    @JoinColumn(name = "COUNTRY", referencedColumnName = "ID_COUNTRY")
    @ManyToOne(fetch = FetchType.LAZY)
    private Country country;
    @JoinColumn(name = "TOWN", referencedColumnName = "ID_TOWN")
    @ManyToOne(fetch = FetchType.LAZY)
    private Town town;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "company", fetch = FetchType.LAZY)
    private List<Search> searchList;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_COMPANY")
    private Integer idCompany;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 100)
    @Column(name = "NAME")
    private String name;
    @Size(max = 128)
    @Column(name = "LOGO")
    private String logo;
    @Basic(optional = false)
    @NotNull
    @Column(name = "AVAILABLE_CREDITS")
    private int availableCredits;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idCompany", fetch = FetchType.LAZY)
    private List<CompanyFolder> companyFolderList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "company", fetch = FetchType.LAZY)
    private List<CompanyAdquiredProduct> companyAdquiredProductList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idCompany", fetch = FetchType.LAZY)
    private List<CompanySector> companySectorList;
    @JoinColumn(name = "COMPANY_ECONOMIC_TYPE", referencedColumnName = "ID_COMPANY_ECONOMIC_TYPE")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private CompanyEconomicType companyEconomicType;
    @JoinColumn(name = "COMPANY_TYPE", referencedColumnName = "ID_COMPANY_TYPE")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private CompanyType companyType;
    @JoinColumn(name = "ID_USER", referencedColumnName = "ID_USER")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private User idUser;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "company", fetch = FetchType.LAZY)
    private List<CompanyAdquiredProfile> companyAdquiredProfileList;

    public Company() {
    }

    public Company(Integer idCompany) {
        this.idCompany = idCompany;
    }

    public Company(Integer idCompany, String name, int availableCredits) {
        this.idCompany = idCompany;
        this.name = name;
        this.availableCredits = availableCredits;
    }

    public Integer getIdCompany() {
        return idCompany;
    }

    public void setIdCompany(Integer idCompany) {
        this.idCompany = idCompany;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLogo() {
        return logo;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }

    public int getAvailableCredits() {
        return availableCredits;
    }

    public void setAvailableCredits(int availableCredits) {
        this.availableCredits = availableCredits;
    }

    @XmlTransient
    public List<CompanyFolder> getCompanyFolderList() {
        return companyFolderList;
    }

    public void setCompanyFolderList(List<CompanyFolder> companyFolderList) {
        this.companyFolderList = companyFolderList;
    }

    @XmlTransient
    public List<CompanyAdquiredProduct> getCompanyAdquiredProductList() {
        return companyAdquiredProductList;
    }

    public void setCompanyAdquiredProductList(List<CompanyAdquiredProduct> companyAdquiredProductList) {
        this.companyAdquiredProductList = companyAdquiredProductList;
    }

    @XmlTransient
    public List<CompanySector> getCompanySectorList() {
        return companySectorList;
    }

    public void setCompanySectorList(List<CompanySector> companySectorList) {
        this.companySectorList = companySectorList;
    }

    public CompanyEconomicType getCompanyEconomicType() {
        return companyEconomicType;
    }

    public void setCompanyEconomicType(CompanyEconomicType companyEconomicType) {
        this.companyEconomicType = companyEconomicType;
    }

    public CompanyType getCompanyType() {
        return companyType;
    }

    public void setCompanyType(CompanyType companyType) {
        this.companyType = companyType;
    }

    public User getIdUser() {
        return idUser;
    }

    public void setIdUser(User idUser) {
        this.idUser = idUser;
    }

    @XmlTransient
    public List<CompanyAdquiredProfile> getCompanyAdquiredProfileList() {
        return companyAdquiredProfileList;
    }
    
    public void setCompanyAdquiredProfileList(List<CompanyAdquiredProfile> companyAdquiredProfileList) {
        this.companyAdquiredProfileList = companyAdquiredProfileList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCompany != null ? idCompany.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Company)) {
            return false;
        }
        Company other = (Company) object;
        if ((this.idCompany == null && other.idCompany != null) || (this.idCompany != null && !this.idCompany.equals(other.idCompany))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.Company[ idCompany=" + idCompany + " ]";
    }

    @XmlTransient
    public List<Search> getSearchList() {
        return searchList;
    }

    public void setSearchList(List<Search> searchList) {
        this.searchList = searchList;
    }

    public String getBusinessName() {
        return businessName;
    }

    public void setBusinessName(String businessName) {
        this.businessName = businessName;
    }

    public String getCif() {
        return cif;
    }

    public void setCif(String cif) {
        this.cif = cif;
    }

    public String getContact() {
        return contact;
    }

    public void setContact(String contact) {
        this.contact = contact;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPostalCode() {
        return postalCode;
    }

    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }

    @XmlTransient
    public List<CompanyVisitedProfile> getCompanyVisitedProfileList() {
        return companyVisitedProfileList;
    }

    public void setCompanyVisitedProfileList(List<CompanyVisitedProfile> companyVisitedProfileList) {
        this.companyVisitedProfileList = companyVisitedProfileList;
    }

    public Province getProvince() {
        return province;
    }

    public void setProvince(Province province) {
        this.province = province;
    }

    public Country getCountry() {
        return country;
    }

    public void setCountry(Country country) {
        this.country = country;
    }

    public Town getTown() {
        return town;
    }

    public void setTown(Town town) {
        this.town = town;
    }

    public String getSummary() {
        return summary;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    public CompanyConfiguration getCompanyConfiguration() {
        return companyConfiguration;
    }

    public void setCompanyConfiguration(CompanyConfiguration companyConfiguration) {
        this.companyConfiguration = companyConfiguration;
    }

    @XmlTransient
    public List<CompanyOrder> getCompanyOrderList() {
        return companyOrderList;
    }

    public void setCompanyOrderList(List<CompanyOrder> companyOrderList) {
        this.companyOrderList = companyOrderList;
    }
    
}
